local zhiqi = fk.CreateSkill {
  name = "emo__zhiqi",
}

zhiqi:addEffect("active", {
  anim_type = "support",
  prompt = "#emo__zhiqi",
  card_num = 1,
  target_num = 0,
  times = function (self, player)
    return 4 - player:usedSkillTimes(zhiqi.name, Player.HistoryPhase)
  end,
  can_use = function(self, player)
    return player:usedSkillTimes(zhiqi.name, Player.HistoryPhase) < 4
  end,
  card_filter = function(self, player, to_select, selected)
    return #selected == 0 and (Fk:getCardById(to_select).trueName == "slash" or Fk:getCardById(to_select).trueName == "jink")
    and not player:prohibitDiscard(to_select)
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    local cardtype = Fk:getCardById(effect.cards[1]).trueName == "slash" and "trick" or "equip"
    room:throwCard(effect.cards, self.name, player, player)
    if player.dead then return end
    room:addPlayerMark(player, "emozhiqiCount-phase", 1)
    local x = player:getMark("emozhiqiCount-phase")
    local ids = room:getCardsFromPileByRule(".|.|.|.|.|"..cardtype, x)
    if #ids == 0 then return false end
    local get = room:askToChooseCard(player, {
      flag = { card_data = { { "emozhiqiGet", ids } } },
      target = player, skill_name = zhiqi.name,
      prompt = "#emo__zhiqi-get",
    })
    local target = player
    local tos = room:askToChoosePlayers(player,
    {
      targets = room.alive_players,
      max_num = 1, min_num = 1, skill_name = zhiqi.name, cancelable = true,
      prompt = "#emo__zhiqi-give:::"..Fk:getCardById(get):toLogString()
    })
    if #tos > 0 then
      target = tos[1]
      room:addPlayerMark(player, "emozhiqiCount-phase", 1)
    end
    room:obtainCard(target, get, false, fk.ReasonGive, player, self.name)
  end,
})

Fk:loadTranslationTable{
  ["emo__zhiqi"] = "置奇",
  [":emo__zhiqi"] = "出牌阶段限四次，你可以弃置一张【杀】/【闪】，从牌堆X张锦囊牌/装备牌中选择一张交给一名角色，然后若该角色不为你，本阶段X的值视为+1（X为你本阶段以此法弃置的牌数）。",
  ["#emo__zhiqi"] = "置奇：弃置【杀】检索锦囊牌 / 弃置【闪】检索装备牌",
  ["emozhiqiGet"] = "获得",
  ["#emo__zhiqi-get"] = "选择获得的牌",
  ["#emo__zhiqi-give"] = "置奇：将 %arg 交给一名角色，点“取消”交给自己",
}

return zhiqi
